package com.demo.common.vo;

import com.demo.common.enums.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Result<T> {

    private Boolean success;
    private Integer code;
    private String message;
    private T data;

    public static <T> Result<T> success() {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), null);
    }

    public static <T> Result<T> success(T data) {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> success(String message) {
        return success(ResultEnum.SUCCESS.getCode(), message, null);
    }

    public static <T> Result<T> success(String message, T data) {
        return success(ResultEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Result<T> success(Integer code, String message, T data) {
        return new Result<>(true, code, message, data);
    }

    public static <T> Result<T> error(String message) {
        return error(500, message, null);
    }

    public static <T> Result<T> error(Integer code, String message) {
        return error(code, message, null);
    }

    public static <T> Result<T> error(Integer code, String message, T data) {
        return new Result<>(false, code, message, data);
    }

    public static <T> Result<T> build(Boolean success, Integer code, String message, T data) {
        return new Result<T>().setSuccess(success).setCode(code).setMessage(message).setData(data);
    }
}
